/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.zx.video.live.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.zx.video.live.entity.TvideoLive;
import com.jeesite.modules.zx.video.live.service.TvideoLiveService;

/**
 * 视频直播管理Controller
 * @author zpp
 * @version 2020-01-19
 */
@Controller
@RequestMapping(value = "${adminPath}/zx/video/live/tvideoLive")
public class TvideoLiveController extends BaseController {

	@Autowired
	private TvideoLiveService tvideoLiveService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public TvideoLive get(String id, boolean isNewRecord) {
		return tvideoLiveService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("zx:video:live:tvideoLive:view")
	@RequestMapping(value = {"list", ""})
	public String list(TvideoLive tvideoLive, Model model) {
		model.addAttribute("tvideoLive", tvideoLive);
		return "modules/zx/video/live/tvideoLiveList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("zx:video:live:tvideoLive:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<TvideoLive> listData(TvideoLive tvideoLive, HttpServletRequest request, HttpServletResponse response) {
		tvideoLive.setPage(new Page<>(request, response));
		Page<TvideoLive> page = tvideoLiveService.findPage(tvideoLive);
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("zx:video:live:tvideoLive:view")
	@RequestMapping(value = "form")
	public String form(TvideoLive tvideoLive, Model model) {
		model.addAttribute("tvideoLive", tvideoLive);
		return "modules/zx/video/live/tvideoLiveForm";
	}

	/**
	 * 保存视频直播管理
	 */
	@RequiresPermissions("zx:video:live:tvideoLive:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated TvideoLive tvideoLive) {
		tvideoLiveService.save(tvideoLive);
		return renderResult(Global.TRUE, text("保存视频直播管理成功！"));
	}
	
	/**
	 * 停用视频直播管理
	 */
	@RequiresPermissions("zx:video:live:tvideoLive:edit")
	@RequestMapping(value = "disable")
	@ResponseBody
	public String disable(TvideoLive tvideoLive) {
		tvideoLive.setStatus(TvideoLive.STATUS_DISABLE);
		tvideoLiveService.updateStatus(tvideoLive);
		return renderResult(Global.TRUE, text("停用视频直播管理成功"));
	}
	
	/**
	 * 启用视频直播管理
	 */
	@RequiresPermissions("zx:video:live:tvideoLive:edit")
	@RequestMapping(value = "enable")
	@ResponseBody
	public String enable(TvideoLive tvideoLive) {
		tvideoLive.setStatus(TvideoLive.STATUS_NORMAL);
		tvideoLiveService.updateStatus(tvideoLive);
		return renderResult(Global.TRUE, text("启用视频直播管理成功"));
	}
	
	/**
	 * 删除视频直播管理
	 */
	@RequiresPermissions("zx:video:live:tvideoLive:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(TvideoLive tvideoLive) {
		tvideoLiveService.delete(tvideoLive);
		return renderResult(Global.TRUE, text("删除视频直播管理成功！"));
	}
	
}